#include "stages.h"

Stages::Stages()
{
    stageInt=0;
    textOut = new MyText(60);

    background.load("grafx/stages/stages.png");
    death.load("grafx/stages/death.png");

    xbounce=-50;
    ybounce=0;

    movingright=false;
    movingdown=true;
}

void Stages::draw(int level)
{

   // music->create_audio_thread( "sounds/titlescreen/endlevel.ogg", "LF" );

    stageInt = level;

    int time=(SDL_GetTicks() +3500);
    bool done = false;
    while(!done)
    {
        if(time > SDL_GetTicks())
        {
                SDL_FillRect(GlobalScreen::screen, NULL, 0x00000000);

                switch( stageInt )
                {
                    case 1:
                        Level1();
                        break;
                    case 2:
                        Level2();
                        break;
                    case 3:
                        Level3();
                        break;
                    case 4:
                        Player_dead();
                        break;
                    default:
                        break;
                }

                SDL_Flip(GlobalScreen::screen);
        }
        else
        {
            done = true;
        }


    }
    //music = NULL;
}

void Stages::Level1()
{
    Background();

    textOut->draw("Starting Level 1", 100, 100);

}

void Stages::Level2()
{
    Background();
    textOut->draw("Starting Level 2", 100, 100);
}

void Stages::Level3()
{   Background();
    textOut->draw("You won!", 100, 100);
}

void Stages::Player_dead()
{
    Background();

    death.draw(250,150);
    textOut->draw("You are DEAD!", 200, 50, 255,0,0);
    textOut->draw("Restarting Level", 200,400);
}

Stages::~Stages()
{
    cout << "destroyed the stage\n";
}

void Stages::Background()
{
    int speed=3;
    int xdist=100;
    int ydist=150;

    if(xbounce<xdist && movingright)
    { xbounce+=speed;}
    if(xbounce > -xdist && !movingright)
    {    xbounce-=speed;   }
    if(xbounce >= xdist)
    {  movingright =false;}
    if(xbounce <= -xdist)
    {  movingright = true;}

    if(ybounce<ydist && movingdown)
    { ybounce+=speed;}
    if(ybounce > -ydist && !movingdown)
    {    ybounce-=speed;   }
    if(ybounce >= ydist)
    {  movingdown =false;}
    if(ybounce <= -ydist)
    {  movingdown = true;}

    background.draw(400+xbounce,-220+ybounce);
    background.draw(400+xbounce,220+ybounce);
    background.draw(-370+xbounce,-220+ybounce);
    background.draw(-370+xbounce,220+ybounce);
}
